package com.cet.base;

/**
 * @program: cet-practice
 * @description:
 * @author: 陈恩涛
 * @create: 2023-04-13 09:57
 **/
public class StringTest {

    static final String MESSAGE = "cid";

    public static void main(String[] args) {

        stringConstantPoolTest();
        System.out.println(toInteger("1"));
    }

    private static void stringConstantPoolTest() {
        String s1 = "c" + "i" + "d"; // java中有常量优化机制 比如说 a=3+6 其中3+6已经被系统默认为是9
        String s2 = "c";
        String s3 = "i";
        String s4 = "d";
        System.out.println(s1 == MESSAGE);
        System.out.println(s2 + s3 + s4 == MESSAGE);

        System.out.println(MESSAGE.substring(1, 2));
    }

    public static int toInteger(String intString) {
        int result = 0;
        for (int i = 0; i < intString.length(); i++) {
            result = result * 10 + intString.charAt(i) - '0';
        }
        return result;
    }
}
